<?php
/**
 * @version     1.0.0
 * @package     com_travel
 * @copyright   Copyright (C) 2013. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 * @author      thinh <dinhducthinh88@yahoo.com> - http://
 */
// No direct access
defined('_JEXEC') or die;

jimport('joomla.application.component.view');
require_once JPATH_COMPONENT.'/helpers/field.php';
/**
 * View to edit
 */
class TravelViewField extends JView
{
	protected $state;
	protected $item;
	protected $form;
	
	/**
	 * Display the view
	 */
	public function display($tpl = null)
	{
		$this->state	= $this->get('State');
		$this->item		= $this->get('Item');
		$this->form		= $this->get('Form');
		
		$id 			= JRequest::getVar( 'id', array(0));
		$fieldValues	= JHTMLTourField::getFieldValues($id);
		
		$this->assignRef('fieldvalues',$fieldValues);
		// Check for errors.
		if (count($errors = $this->get('Errors'))) {
            throw new Exception(implode("\n", $errors));
		}

		$this->editToolbar();
		parent::display($tpl);
	}
	
	
	function editToolbar()
	{
		JRequest::setVar('hidemainmenu', true);

		$user		= JFactory::getUser();
		$userId		= $user->get('id');
		$checkedOut	= !($this->item->checked_out == 0 || $this->item->checked_out == $userId);
		
		// If not checked out, can save the item.
		if (!$checkedOut) {
			JToolBarHelper::apply('field.apply');
			JToolBarHelper::save('field.save');
			JToolBarHelper::save2new('field.save2new');
		}
		JToolBarHelper::title( JText::_('COM_TRAVEL_TITLE'), 'adsmanager' );
		JToolBarHelper::cancel('field.cancel');	
	}
}